// by Xeno

//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "math\fn_getRanPointCircleBig.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_center", "_radius", "_center_x", "_center_y", "_ret_val", "_co", "_angle", "_x1", "_y1", "_helper","_slope_dist","_isFlat"];
DEFAULT_PARAM(_center,0,[]);
DEFAULT_PARAM(_radius,1,100);
DEFAULT_PARAM(_min_dist,2,0);
DEFAULT_PARAM(_slope_dist,3,0);
if (_radius < _min_dist) then { _min_dist = 0; };

_center_x = _center select 0;_center_y = _center select 1;
_ret_val = [];_co = 0;
while {count _ret_val == 0 && _co < 100} do {
	_angle = floor (random 360);
	_randradius = _min_dist + random(_radius - _min_dist);
	_x1 = _center_x - (_randradius * sin _angle);
	_y1 = _center_y - (_randradius * cos _angle);
	_isFlat = [_x1, _y1, 0] isFlatEmpty [
		9,	//--- Minimal distance from another object
		0,				//--- If 0, just check position. If >0, select new one
		0.7,				//--- Max gradient
		13,	//--- Gradient area
		0,				//--- 0 for restricted water, 2 for required water,
		false,				//--- True if some water can be in 25m radius
		objNull			//--- Ignored object
	];
	if (count _isFlat > 0 && {!isOnRoad _isFlat} && {(_isFlat select 2) >= 0}) exitWith {
		_ret_val = ASLToATL _isFlat;
	};
	if (count _ret_val == 0) then {_co = _co + 1};
};
if (count _ret_val <= 0) then { _ret_val = _center findEmptyPosition [_min_dist,_radius,"Land_Cargo_HQ_V1_F"]; };
TRACE_1("End",_ret_val);
TMFPROFILERSTOP;
_ret_val
